package com.zero.rocketmq.api.base.producer.onway;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * 单向发送消息,只管将消息发送出去，不能保证消息是否发送成功
 */
public class OnwayProducer {

    public static void main(String[] args) throws MQClientException {

        DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
        producer.setNamesrvAddr("10.185.3.41:9876");
        producer.start();

        try {
            for (int i = 0; i < 10; i++) {

                Message message = new Message();
                message.setTopic("TopicTest");
                message.setTags("TagA");
                message.setKeys("OrderID188");
                message.setBody("Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
                producer.sendOneway(message);
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        producer.shutdown();
    }
}
